<?php
/**
 * Created by PhpStorm.
 * User: Shine
 * Date: 2019-02-23
 * Time: 15:17
 */

namespace app\m\controller;

use think\Db;

class Index
{

    public function index()
    {


    }

    public function set_cache()
    {
        $redis = redis();


        $qs = Db::query('select id,name,shortname,area,type from x1_unit');

        foreach ($qs as $r) {
            $k = 'U' . $r['id'];

            $redis->set($k, igbinary_serialize($r));

        }

        $qs = Db::query('select id,name,type,area from x1_school');
        foreach ($qs as $r) {
            $k = 'S' . $r['id'];

            $redis->set($k, igbinary_serialize($r));

        }


    }

    public function area()
    {

        $qs = Db::query("select * from area where pc='41'");
        foreach ($qs as $a) {
            $code = $a['code'];
            $c = substr($code, 0, 4);

            $sql = "update area set code='$c' where id=".$a['id'];

            Db::execute($sql);

            //echo $sql,"\r\n";
        }


    }


}
